import os
import sys
import platform

OS_NAME = platform.system();
LIB_DIR=os.environ['LIB_DIR'];
BIN_DIR=os.environ['BIN_DIR'];

env=DefaultEnvironment().Clone()
RIVE_CPP_FILES = Glob("rive-cpp/src/generated/*.cpp") + \
  Glob("rive-cpp/src/generated/animation/*.cpp") + \
  Glob("rive-cpp/src/generated/constraints/*.cpp") + \
  Glob("rive-cpp/src/generated/shapes/*.cpp") + \
  Glob("rive-cpp/src/generated/shapes/paint/*.cpp") + \
  Glob("rive-cpp/src/generated/bones/*.cpp") + \
  Glob("rive-cpp/src/*.cpp") + \
  Glob("rive-cpp/src/core/*.cpp") + \
  Glob("rive-cpp/src/core/field_types/*.cpp") + \
  Glob("rive-cpp/src/importers/*.cpp") + \
  Glob("rive-cpp/src/shapes/paint/*.cpp") + \
  Glob("rive-cpp/src/shapes/*.cpp") + \
  Glob("rive-cpp/src/math/*.cpp") + \
  Glob("rive-cpp/src/animation/*.cpp") + \
  Glob("rive-cpp/src/constraints/*.cpp") + \
  Glob("rive-cpp/src/bones/*.cpp");

SOURCES=Glob('base/*.c') + Glob('*.c') + Glob('*.cpp') + RIVE_CPP_FILES + Glob('rive/*.cpp');

APP_CXXFLAGS = ''
if platform.system() == 'Windows':
  APP_CXXFLAGS += ' /std:c++latest -DRIVE_BUILD -D_USE_MATH_DEFINES '
else:
  APP_CXXFLAGS += ' -std=c++17 '

env['CXXFLAGS'] = env['CXXFLAGS'] + APP_CXXFLAGS

EXPORT_DEF=''
if OS_NAME == 'Windows' and os.environ['TOOLS_NAME'] == '':
  EXPORT_DEF = ' /DEF:"src/rive.def" '

if 'BUILD_SHARED' in os.environ and os.environ['BUILD_SHARED'] == 'True':
  LIBS=['awtk'];
  LINKFLAGS=env['LINKFLAGS'] + EXPORT_DEF 
  env.SharedLibrary(os.path.join(BIN_DIR, 'rive'), SOURCES, LIBS=LIBS, LINKFLAGS=LINKFLAGS);
else:
  env.Library(os.path.join(LIB_DIR, 'rive'), SOURCES);

